﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FDSimpleModelGenerator.Common
{
    /// <summary>
    /// 使用默认缓存
    /// </summary>
    public class CacheManager : ICache
    {
        private static readonly ICache _cache = new DefaultCache();
        public static CacheManager Default => new CacheManager();

        /// <summary>
        /// 获取值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public T Get<T>(string key)
        {
            return _cache.Get<T>(key);
        }

        /// <summary>
        /// 获取，不存在则加入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="addIfNotExists"></param>
        /// <param name="expires"></param>
        /// <returns></returns>
        public T Get<T>(string key, Func<T> addIfNotExists, TimeSpan expires)
        {
            return _cache.Get(key, addIfNotExists, expires);
        }

        /// <summary>
        /// 设置值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expires"></param>
        /// <returns></returns>
        public bool Set<T>(string key, T value, TimeSpan expires)
        {
            return _cache.Set(key, value, expires);
        }
    }
}
